package com.ruoyi.project.member.privilegepackage.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.MoneyUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.member.privilegepackage.mapper.PrivilegePackageMapper;
import com.ruoyi.project.member.privilegepackage.domain.PrivilegePackage;
import com.ruoyi.project.member.privilegepackage.service.IPrivilegePackageService;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;

/**
 * 会员特权Service业务层处理
 * 
 * @author shixiangwen
 * @date 2020-03-11
 */
@Service
@DataSource(value = DataSourceType.ACCOUNT)
public class PrivilegePackageServiceImpl implements IPrivilegePackageService {
	@Autowired
	private PrivilegePackageMapper privilegePackageMapper;

	/**
	 * 查询会员特权
	 * 
	 * @param id 会员特权ID
	 * @return 会员特权
	 */
	@Override
	public PrivilegePackage selectPrivilegePackageById(Long id) {
		return privilegePackageMapper.selectPrivilegePackageById(id);
	}

	/**
	 * 查询会员特权列表
	 * 
	 * @param privilegePackage 会员特权
	 * @return 会员特权
	 */
	@Override
	public List<PrivilegePackage> selectPrivilegePackageList(PrivilegePackage privilegePackage) {
		List<PrivilegePackage> list = privilegePackageMapper.selectPrivilegePackageList(privilegePackage);
		list.forEach(item -> {
			item.setYuan(MoneyUtil.fee2yuan(item.getFee()));
			item.setDiscountYuan(MoneyUtil.fee2yuan(item.getDiscountFee()));
		});
		return list;
	}

	/**
	 * 新增会员特权
	 * 
	 * @param privilegePackage 会员特权
	 * @return 结果
	 */
	@Override
	public int insertPrivilegePackage(PrivilegePackage privilegePackage) {
		privilegePackage.setCreateTime(DateUtils.getNowDate());
		return privilegePackageMapper.insertPrivilegePackage(privilegePackage);
	}

	/**
	 * 修改会员特权
	 * 
	 * @param privilegePackage 会员特权
	 * @return 结果
	 */
	@Override
	public int updatePrivilegePackage(PrivilegePackage privilegePackage) {
		privilegePackage.setUpdateTime(DateUtils.getNowDate());
		return privilegePackageMapper.updatePrivilegePackage(privilegePackage);
	}

	/**
	 * 删除会员特权对象
	 * 
	 * @param ids 需要删除的数据ID
	 * @return 结果
	 */
	@Override
	public int deletePrivilegePackageByIds(String ids) {
		return privilegePackageMapper.deletePrivilegePackageByIds(Convert.toStrArray(ids));
	}

	/**
	 * 删除会员特权信息
	 * 
	 * @param id 会员特权ID
	 * @return 结果
	 */
	@Override
	public int deletePrivilegePackageById(Long id) {
		return privilegePackageMapper.deletePrivilegePackageById(id);
	}
}
